#ifndef __MOUSE_H
#define __MOUSE_H

#include <SDL/SDL.h>

#include "event.h"

/** 
  * The MOUSEBUTTONS represents the buttons from 1 to 255
  * COMP_MOUSE_X/Y represents the axes X/Y (mousemotions)
  */
#define MOUSEBUTTONS 255
#define COMP_MOUSE_X MOUSEBUTTONS+1
#define COMP_MOUSE_Y MOUSEBUTTONS+2

/**
  * This class represents to the mouse.
  * It's able to receive specific SDL_Events and to answer to a request of the
  * generic events. To do it, it uses an actual state and other old.
  * When a new event happens the actual state is updated @see receiveEvent.
  * Then a request about the event or state can be do it,
  * @see is EventTriggered. Later the mouse is update and the old and actual
  * state is the same.
  */
class Mouse
{
  public:
    /**
      * Set all the buttons to NO_PRESSED
      */
    Mouse();
    
    /**
      * Don't do really much
      */
    ~Mouse();
    
    /** Update the old state to the actual */
    void update();
    
    /**
      * Modify the actual state with the event.
      * @param event is a SDL_Event get it of the event queue.
      */
    void receiveEvent(const SDL_Event &event);
    
    /** Return if a event happened or not, and how many did it.
      * If was a motion event: ON_RELEASE and ON_RELEASING returns false.
      *
      * @param event is the event is going to be checked.
      * @param magnitude is a write parameter to know "how many event" happened.
      * In mouse always be 1 is the event happened (mouse buttons) or the 
      * component X/Y (mouse motion).
      *
      * @returns true if the event happened.
      */
    bool isEventTriggered(const Event &event,Sint32 &magnitude);
    
  protected:
    /** 
      * Indicates the old position of the axes X/Y
      */
    Uint16 m_oldPosX;
    Uint16 m_oldPosY; 
    
    /** 
      * Indicates the actual position of the axes X/Y
      */
    Uint16 m_actualPosX;
    Uint16 m_actualPosY;
    
    /**
      * It's array each element is a button.
      * It's the old state. If the position SDL_BUTTON_LEFT is true
      * means left button has been pressed.
      */
    bool m_oldButtons[MOUSEBUTTONS];
    
    /**
      * The same @see m_oldButtons but save the actual state
      */
    bool m_actualButtons[MOUSEBUTTONS];
};

#endif
